<?php
define('FPDF_FONTPATH','/Library/WebServer/Documents/derby/font/');

require( 'fpdf.php' );
require( 'getresults.php' );

class PDF extends FPDF
{
function EventTable($event)
{
    $this->Image('logo.png',5,5,33);

    $this->SetXY( 40, 15 );

    $this->SetFont('','B','24');
    $this->Cell(40,10,$event['name'],15);
    $this->Ln();

    $this->SetXY( 10, 45 );

    $this->SetFont('','B','10');
    $this->SetFillColor(128,128,128);
    $this->SetTextColor(255);
    $this->SetDrawColor(92,92,92);
    $this->SetLineWidth(.3);

    $this->Cell(70,7,"Team 1",1,0,'C',true);
    $this->Cell(20,7,"Score 1",1,0,'C',true);
    $this->Cell(70,7,"Team 2",1,0,'C',true);
    $this->Cell(20,7,"Score 2",1,0,'C',true);
    $this->Ln();

    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');

    $fill = false;

    foreach($event['games'] as $game)
    {
      $this->SetFont('Times',((int)$game['score1']>(int)$game['score2'])?'BI':'');
      $this->Cell(70,6,$game['team1'],'LR',0,'L',$fill);
      $this->Cell(20,6,$game['score1'],'LR',0,'R',$fill);
      $this->SetFont('Times',((int)$game['score1']<(int)$game['score2'])?'BI':'');
      $this->Cell(70,6,$game['team2'],'LR',0,'L',$fill);
      $this->Cell(20,6,$game['score2'],'LR',0,'R',$fill);
      $this->Ln();
      $fill =! $fill;
    }
    $this->Cell(180,0,'','T');
}
}

$pdf = new PDF();
$pdf->SetFont('Arial','',10);
foreach( getResults() as $event ) {
  $pdf->AddPage();
  $pdf->EventTable($event);  
}
$pdf->Output();
?>

